import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)
import Layout from '@/layout'

var router = new Router({
  // 'mode': 'history', //去掉URL的#号，需要配置服务器http://router.vuejs.org/zh-cn/essentials/history-mode.html
  // 'linkActiveClass': 'active',
  scrollBehavior(to, from, savedPosition) {
    if (savedPosition) {
      return savedPosition
    } else {
      return { x: 0, y: 0 }
    }
  },
  routes: [
    // {
    //     path: '*',
    //     redirect: '/home'
    // },
    {
      path: '/',
      redirect: '/index'
    },
    {
      path: '/login',
      component: resolve => require(['_views/login/login.vue'], resolve),
      meta: {
        title: '登录',
        keepAlive: true
      }
    },
    {
      path: '/index',
      component: resolve => require(['_views/index.vue'], resolve),
      meta: {
        title: '首页',
        keepAlive: true
      }
    }
  ]
})
router.beforeEach((to, from, next) => {
  if (!to.meta.title) {
    document.title = to.query.title
  } else {
    document.title = to.meta.title
  }
  next()
})
export default router
